<template>
  <div id="index">
    <el-container>
      <!-- 头 -->
      <myHeader></myHeader>
      <!-- <el-header>
        <div class="head">
          <ul>
            <li>
              <div @click="login">登录|注册</div>
            </li>
            <li><div @click="myfavorite">我的收藏</div></li>
            <li><div @click="myhouse">我的租房</div></li>
            <li><div @click="myroomie">我的室友</div></li>
            <li><div @click="personal">个人中心</div></li>
          </ul>
        </div>
      </el-header> -->

      <!-- 中 -->
      <el-main>
        <div class="header">
          <!-- 轮播图 -->
          <div class="block">
            <el-carousel height="600px">
              <el-carousel-item v-for="item in imgList" :key="item.id">
                <img :src="item.idView" class="" style="width: 100%" />
              </el-carousel-item>
            </el-carousel>
          </div>
          <!-- 轮播图结束 -->
          <!-- 导航栏 -->
          <div class="house-logo">
            <div class="logo">
              <i class="icon iconfont icon-shouye"></i>
            </div>
          </div>
          <el-menu
            :default-active="activeIndex"
            class="el-menu-demo"
            mode="horizontal"
            @select="handleSelect"
          >
            <el-menu-item index="1">首页</el-menu-item>
            <el-menu-item index="2" @click="allhouse">房源</el-menu-item>
            <el-menu-item index="3" @click="uphouse">发布房源</el-menu-item>
            <el-menu-item index="4" @click="post">帖子</el-menu-item>
          </el-menu>
          <div class="line"></div>
          <!-- 导航栏结束 -->
          <!-- 文字装饰 -->
          <div class="wenzi"></div>
          <!-- 文字装饰结束 -->
          <!-- 搜索框 -->
          <div class="search">
            <form action="" method="post">
              <input v-model="title" placeholder="请输入相关房源标题" name="keyword" type="text" />
              <button type="submit" @click="$router.push('/allhouse?title=' + title)"></button>
            </form>
          </div>
          <!-- 搜索框结束 -->
        </div>
        <!-- 导航栏 -->
        <!-- <el-menu
          :default-active="activeIndex"
          class="el-menu-demo"
          mode="horizontal"
          @select="handleSelect"
        >
          <el-menu-item index="1">首页</el-menu-item>
          <el-menu-item index="2" @click="allhouse">房源</el-menu-item>
          <el-menu-item index="3" @click="post">帖子</el-menu-item>
        </el-menu>
        <div class="line"></div> -->
        <!-- 导航栏结束 -->
        <!-- 轮播图 -->
        <!-- <div class="block">
              <el-carousel height="500px">
                <el-carousel-item v-for="item in imgList" :key="item.id">
                  <img :src="item.idView" class="" style="width: 100%" />
                </el-carousel-item>
              </el-carousel>
            </div> -->
        <!-- 轮播图结束 -->

        <div class="bgmask"></div>
        <!-- 精选房源 -->
        <div class="box_hd">
          <h2 class="title">精选房源</h2>
          <p class="show_top_l_p">Boutique apartment</p>
        </div>
        <el-row class="gh">
          <el-col
            :span="8"
            v-for="(o, index) in goodhouse"
            :key="o"
            :offset="index > 0 ? 2 : 0"
          >
            <el-card :body-style="{ padding: '0px' }">
              <img
                :src="o.firstImage"
                class="image"
                @click="$router.push('/housedetail?id=' + o.id)"
              />
              <div style="padding: 14px">
                <span class="goodtitle">{{ o.title }}</span>
                <span class="goodarea">面积：{{ o.area }}平米 </span>
                <span class="goodmoney">{{ o.money }}元/月</span>
              </div>
            </el-card>
          </el-col>
        </el-row>
        <!-- 精选房源结束 -->
      </el-main>

      <!-- 尾 -->
      <el-footer><myFooter style="margin-left: 260px"></myFooter></el-footer>
    </el-container>
  </div>
</template>

<script>
import myHeader from "../components/myHeader";
import myFooter from "../components/myFooter.vue";
import request from "@/utils/request";
export default {
  components: {
    myHeader,
    myFooter,
  },
  data() {
    return {
      title:'',
      activeIndex: "1",
      activeIndex2: "1",
      activeName: "first",
      //轮播图图片
      imgList: [
        { id: 1, idView: require("@/assets/carousel/house1.jpg") },
        { id: 2, idView: require("@/assets/carousel/house2.jpg") },
        { id: 3, idView: require("@/assets/carousel/house3.jpg") },
        { id: 3, idView: require("@/assets/carousel/house4.jpg") },
      ],

      //精选房源
      currentDate: new Date(),
      goodhouse: [],
      goodhouse: [],

      //获取localStorage中保存的后台返回的用户信息
      user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
    };
  },
  async created() {
    const res = await request.get(`/house/listhouse`);
    if (res.code === 200) {
      this.goodhouse = res.data;
      console.log(this.goodhouse)
      for (let i = 0; i < this.goodhouse.length; i++) {
        const imgRes = await request.get(`/house/firstimg/${this.goodhouse[i].houseAccount}`);
        if (imgRes.code === 200) {
          this.$set(this.goodhouse[i], "firstImage", imgRes.data);
        }
      }
    } else {
      this.$notify.error(res.msg);
    }
  },
  methods: {
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    // 路由跳转
    allhouse() {
      this.$router.push("/allhouse");
    },
    post() {
      this.$router.push("/post");
    },
    login() {
      this.$router.push("/login");
    },

    fl() {
      this.$router.push("/fl");
    },
    uphouse() {
      this.$router.push("/uphouse");
    },
    housedetail() {
      this.$router.push("/housedetail");
    },
    myfavorite() {
      this.$router.push("/myfavorite");
    },
    myhouse() {
      this.$router.push("/myhouse");
    },
    myroomie() {
      this.$router.push("/myroomie");
    },
    personal() {
      this.$router.push("/personal");
    },
  },
};
</script>

<style scoped>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

/* 整体结构样式 */
.el-header,
.el-footer {
  /* background-color: #b3c0d1; */
  color: #333;
  text-align: center;
  line-height: 60px;
  display: flex;
}

.el-main {
  /* background-color: #e9eef3;
  color: #333; */
  text-align: center;
  padding: 0;
  background-color: #f7f7f7;
  /* line-height: 160px; */
}

/* 头部样式 */

.el-header {
  background-color: rgba(0, 0, 0);
  color: white;
  height: 30px !important;
}

.el-link.el-link--default span {
  color: white;
}

.el-header .head .el-link:hover {
  color: #ffac38;
}

.el-header .head {
  margin-left: auto;
  display: flex;
  align-items: center;
  padding-right: 100px;
}

.head ul li {
  display: inline-block;
  /* line-height: 60px; */
  padding: 10px;
  cursor: pointer;
  font-size: 13px;
}

ul li div {
  float: left;
  padding-top: 20px;
}

/* 文字装饰样式 */
.wenzi {
  position: absolute;
  margin: 120px auto 0 auto;
  text-align: center;
  background-image: -webkit-image-set(url(../assets/index1.png) 2x);
  background-repeat: no-repeat;
  height: 69px;
  width: 540px;
  top: 15%;
  left: 50%;
  margin-left: -270px;
  z-index: 5;
  z-index: 5;
}
/* 搜索框样式 */
* {
  box-sizing: border-box; /*宽度和高度会包括内边距和边框*/
}

div.search {
  padding: 10px 0;
  position: absolute;
  z-index: 5;
  top: 45%;
  left: 50%;
  margin-left: -250px;
}

form {
  position: relative;
  width: 500px;
  margin: 0 auto; /*设置宽度后，居中*/
  border-radius: 0 2px 2px 0;
}

input,
button {
  border: none; /*无边框样式；元素的总宽度和高度包括边框的宽度 */
  outline: none; /*无轮廓样式；轮廓是在元素周围绘制的一条线，在边框之外并且可能与其他内容重叠，以凸显元素，元素的总宽度和高度不受轮廓线宽度的影响。*/
}

.search input {
  width: 100%;
  height: 42px;
  padding-left: 13px;
  /* border: 2px solid #c5464a; */
  border-radius: 2px; /*border-radius 属性用于向元素添加圆角边框：*/
  /* background: transparent; 背景透明 */
  color: black;
  font-size: 15px;
}

input::-webkit-input-placeholder {
  font-size: 15px;
  color: #bdc3c7;
}

.search button {
  height: 42px;
  width: 42px;
  cursor: pointer; /*cursor属性定义了鼠标指针放在一个元素边界范围内时所用的光标形状*/
  position: absolute;
  background: #1c92d2;
  border-radius: 0 19px 19px 0;
  width: 100px;
  right: 0;
  font-size: 18px;
  border-radius: 0 2px 2px 0;
}
.search button:hover {
  background-color: #00b0db; /*点击搜索按钮时的背景颜色*/
}

/* 在<button>元素后面插入内容，并设置所插入内容的样式： */
.search button:before {
  content: "搜索"; /*插入的内容*/
  font-size: 18px; /*插入内容的字体大小*/
  color: white; /*插入内容的字体颜色*/
}

/* 选择标签样式 */
.el-tabs__active-bar {
  height: 0;
}

.el-tabs__nav-wrap::after {
  height: 0;
}

.el-tabs__nav {
  padding-left: 20px;
  padding-top: 10px;
}

/* 轮播图样式 */
.block {
  width: 100%;
  /* height: 200px; */
  overflow: hidden;
}

.el-carousel__indicators {
  list-style: none;
  margin: 0;
  z-index: 2;
  display: flex;
  position: absolute;
  width: 100%;
}

/* 导航栏样式 */
.house-logo {
  float: left;
  position: absolute;
  z-index: 5;
  top: 65px;
  left: 90px;
  color: white;
  width: 200px;
  height: 100px;
  cursor: pointer;
}

.logo {
  position: relative;
  width: 100px;
  height: 50px;
  margin-top: -2px;
}

.icon-shouye {
  font-size: 55px;
  margin-left: 84px;
}

.haozu {
  position: absolute;
  top: 3px;
  bottom: 20px;
  left: 60px;
  font-size: 35px;
}

.haozu1 {
  position: absolute;
  top: 45px;
  bottom: 20px;
  left: 60px;
  font-size: 15px;
}

.el-icon-s-home:before {
  content: "\e7b9";
  position: absolute;
  z-index: 5;
  font-size: 60px;
  color: white;
  top: 0px;
  left: 0px;
}

.el-menu-item * {
  text-decoration: none;
}

.el-menu {
  background-color: rgba(225, 225, 225, 0);
}

.el-menu-item {
  color: white !important;
  font-size: 16px;
  text-shadow: 0 0 5px rgb(0 0 0 / 30%);
  font-weight: 900;
  font-size: 18px;
}

.el-menu-item:hover {
  background-color: rgba(225, 225, 225, 0) !important;
  color: white !important;
}

.bgmask {
  background: url(../assets/bgmask.jpg) no-repeat top center;
  height: 450px;
  display: block;
  position: relative;
}

.el-menu--horizontal {
  border-right: none;
  position: absolute;
  top: 65px;
  left: 230px;
  z-index: 5;
  border-bottom: solid 0px rgba(225, 225, 225, 0) !important;
}

.el-menu--horizontal > .el-menu-item.is-active {
  border-bottom: solid 0px rgba(225, 225, 225, 0);
}

/* 精选房源样式 */
.box_hd {
  /* position: relative; */
  width: 100%;
  height: 60px;
  line-height: 60px;
  /* border-bottom: 2px #000000 solid; */
  font-size: 18px;
  margin-top: 80px;
}

.title {
  /* position: absolute; */
  top: -9px;
  font-size: 24px;
  font-weight: 400;
  color: #333;
  line-height: 38px;
  height: 38px;
  overflow: hidden;
  font-family: HELVETICANEUELTPRO-THEX, "微软雅黑";
}

.show_top_l_p {
  height: 26px;
  font-size: 14px;
  color: #b1b1b1;
  line-height: 26px;
  overflow: hidden;
  font-family: HELVETICANEUELTPRO-THEX, "微软雅黑";
}

.gh {
  width: 1200px;
  margin: 80px auto;
}

.el-col-8 {
  width: 380px;
  margin: 15px 15px 15px 0;
  cursor: pointer;
}

.el-col-offset-2 {
  margin-left: auto;
  /* margin-top: 20px; */
}

.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  height: 250px;
  display: block;
}

.gh .goodtitle {
  float: left;
  font-family: Arial, "微软雅黑";
  margin-left: -6px;
  font-size: 16px;
  font-weight: 600;
}
span.goodtitle {
  width: 360px;
  height: 20px;
  overflow: hidden;
  display: -webkit-box;
}
.gh .goodarea {
  float: left;
  color: #999;
  /* font-size: 12px; */
  font-family: Arial, "微软雅黑";
  margin: 10px;
}

.gh .goodmoney {
  float: left;
  color: #eb5f00;
  /* font-size: 12px; */
  font-family: Arial, "微软雅黑";
  font-size: 18px;
  font-weight: 700;
  float: right;
  margin: 10px 10px 10px 10px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}
</style>
